package com.shijiu.controller;

import com.shijiu.annotation.RepeatSubmit;
import com.shijiu.pojo.Order;
import com.shijiu.service.OrderService;
import com.shijiu.utils.UserThreadLocal;
import com.shijiu.common.Result;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author xlj
 * @Date Created in  2023/3/18 14:30
 * @DESCRIPTION:
 * @Version V1.0
 */
@RestController
@RequestMapping("order")
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation("查询订单列表")
    @GetMapping("orderlist")
    public Result getOrderList(){
        return orderService.selectOrderList((Integer) UserThreadLocal.get().get("shopId"));
    }
    @ApiOperation("查询订单列表")
    @PostMapping("orderlistByPage")
    public Result getOrderList(@RequestBody Map<String, Object> requestBodyMaps){
        return orderService.selectOrderListByPage((Integer) UserThreadLocal.get().get("shopId"),requestBodyMaps);
    }
    @ApiOperation("修改订单状态")
    @RepeatSubmit(interval = 2000, message = "接口请求过于频繁")
    @PostMapping("update")
    public Result updateStatus(@RequestBody Order order){
        return orderService.updateStatus(order);
    }

    @ApiOperation("逻辑删除订单")
    @RepeatSubmit(interval = 2000, message = "接口请求过于频繁")
    @GetMapping("delete/{id}")
    public Result deleteOrder(@PathVariable("id") Integer id){
        Order order = new Order();
        order.setId(id);
        order.setAdminDelete(true);
        orderService.updateById(order);
        return Result.success("删除订单成功");
    }

    @ApiOperation("查看订单详情-根据订单id,查看订单的所有菜品以及数量")
    @GetMapping("showfood/{id}")
    public Result showOrderFood(@PathVariable("id") Integer id){

        return orderService.showFood(id);
    }
}
